<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* ul {
        大写
            text-transform: uppercase;
        } */    
        :root {
            --awidth: 100px;
        }
        a {
            text-decoration: none;
        }
        body {
            background-color: rgb(34, 34, 34);
            display: flex;
            justify-content: center; /* 让nav水平居中 */
            padding-top: 100px; /* 替代原来的nav margin-top，布局更稳定 */
        } 
        nav {
            position: relative;
            display: inline-flex;
            justify-content: center;
            align-items: center;
            border-radius: 8px;
            background-color: rgb(14, 14, 14);
            box-shadow: 2px 2px 5px rgb(63, 63, 63);
        }
        nav a {  
            display: block;
            position: relative;
            z-index: 1;
            width: var(--awidth);
            font-size: 23px;
            color: aliceblue;
            text-align: center;
            line-height: 60px;
            text-transform: uppercase;
        }
        .animation {
            position: absolute; /* 脱离文档流，不占用flex空间 */
            left: 0;
            /* 层叠 0*/
            z-index: 0;
            background-color: rgb(56, 40, 40);
            height: 100%;
            width: var(--awidth);
            border-radius: 8px;
            transition: all 0.2s;
        }
        /* 动画效果 */
        nav a:first-child:hover~.animation {
            left: calc(var(--awidth) * 0);
        }
        nav a:nth-child(2):hover~.animation{
            left: calc(var(--awidth) * 1);
        }
        nav a:nth-child(3):hover~.animation{
            left: calc(var(--awidth) * 2);
        }
        nav a:nth-child(4):hover~.animation{
            left: calc(var(--awidth) * 3);
        }
        nav a:nth-child(5):hover~.animation{
            left: calc(var(--awidth) * 4);
        }
    </style>
</head>
<body>
    <nav>
        <a href="#">一</a>
        <a href="#">二</a>
        <a href="#">三</a>
        <a href="#">四</a>
        <a href="#">五</a>
        <div class="animation"></div>
    </nav>
</body>
</html>